package projetA;

import javax.swing.JLabel;


public class ThreadImageCentre extends Thread{
	private BtnAdmin sup;
	private JLabel image;
	private int yOrigine;
	private boolean etape2;
	private boolean retour;
	
	public ThreadImageCentre(BtnAdmin a){
		this.sup = a;
		this.retour = false;
		etape2 = false;	
		image = sup.getMain().getImageCentre();
		this.yOrigine = image.getY();
	}
	
	public void run() {
		
		
		sup.getMain().setPauseThread(false);
		sup.getMain().btnGo.setEnabled(false);
		
		while(!retour && !sup.getMain().getPauseThread() ){      
	    	  if(etape2 == false){
	    		  image.setLocation(image.getX(), image.getY()-1);
	    		  if(image.getY() == (yOrigine-25)){
		    		  etape2 = true;
		    	  }
	    	  }else{
	    		  image.setLocation(image.getX(), image.getY()+1);
	    		  if(image.getY() == yOrigine){
	    			  retour = true;
	    			  etape2= false;
	    			  sup.getMain().setPauseThread(false);
	    		  }
	    	  }
		      try {		    	  
		    	  Thread.sleep(100);
		      }
		      catch (InterruptedException ex) {}
		      while(sup.getMain().getPauseThread() == true){
		    	  try {
					Thread.sleep(100);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		      }
	    }
		
		if (retour == true){
	    	sup.createNewInstanceThreads();
	    	sup.getMain().btnStop.setEnabled(false);
	    	sup.getMain().btnGo.setEnabled(true);
	    }
	}
}
